from .models import StudentEvaluateEnvironment as s_e_save1  #学期总评 
from .models import StudentEvaluateOrganizaton as s_e_save2  #校内机构
from .models import Student,CourseTimetable,Teacher,StudentEvaluateTeacher,ClassAdmin
from .models import TeacherEvaluateClass as t_e_class #评价班级
from .models import TeacherEvaluateOrganization as t_e_o #教师评价机构
from .models import StudentEnvironmentAdvice  as s_e_advice #推送学生意见


"""
获取学生待评价数据
"""

def get_hold_s_evaluation(u_id):
	student =Student.objects.get(student_id=u_id)
	class_room_s = student.class_room
	class_room_list = []
	class_room_list = class_room_s.split(',')
	v_list = []
	for i in class_room_list:
		course = CourseTimetable.objects.get(course_id=i)
		teacher = Teacher.objects.get(teacher_id = course.teacher_id)
		v_list.append({'course_id':course.course_id,'teacher_id':course.teacher_id,'course_name':course.name,'teacher_name':teacher.user_name})
	v_list.append(student)
	return v_list



"""
处理学生评价数据
"""

#学生评价总体
def save_p_eva(request):
	zt = request.POST['zt']
	jxhj = request.POST['jxhj']
	zshj = request.POST['zshj']
	yshj = request.POST['yshj']
	ztpjw = request.POST['ztpjw']
	ztpjr = request.POST['ztpjr']
	jxhjw = request.POST['jxhjw']
	jxhjr = request.POST['jxhjr']
	zshjw = request.POST['zshjw']
	zshjr = request.POST['zshjr']
	yshjw = request.POST['yshjw']
	yshjr = request.POST['yshjr']
	bcpj = request.POST['bcpj']
	org_1 = org_2 =org_3 = org_4 = org_5 = org_6 =''
	organization=''
	if 'org_1' in request.POST:
		org_1 = request.POST['org_1']
		organization=organization+','+org_1
	if 'org_2' in request.POST:
		org_2 =request.POST['org_2']
		organization=organization+','+org_2
	if 'org_3' in request.POST:
		org_3 =request.POST['org_3']
		organization=organization+','+org_3
	if 'org_4' in request.POST:
		org_4 =request.POST['org_4']
		organization=organization+','+org_4
	if 'org_5' in request.POST:
		org_5 =request.POST['org_5']
		organization=organization+','+org_5
	if 'org_6' in request.POST:
		org_6 =request.POST['org_6']
		organization=organization+','+org_6 
	u_id = request.session.get('u_id','')
	s_e_save1.objects.create(student_id=u_id,totality=zt,teaching_environment=jxhj,accommodation_environment=zshj,diet_environment=yshj,teaching_environment_proposal=jxhjw,accommodation_environment_proposal=zshjw,diet_environment_proposal=yshjw,totality_proposal=ztpjw,totality_h=ztpjr,teaching_environment_h=jxhjr,accommodation_environment_h=zshjr,diet_environment_h=yshjr)
	if bcpj!='' :
		s_e_save2.objects.create(student_id=u_id,organization=organization,proposal=bcpj)
	

def save_ev_t(request):
	khfd = request.POST['khfd']
	t_id = request.POST['teacher_id']
	s_id = request.session.get('u_id')
	c_id = request.POST['course_id']
	ktfc = request.POST['ktfc']
	rwml = request.POST['rwml']
	totw = request.POST['totw']
	totr = request.POST['totr']
	StudentEvaluateTeacher.objects.create(student_id =s_id,teacher_id=t_id,class_id=c_id,class_mien=ktfc,after_school_program=khfd,teacher_charm=rwml,proposal_of_teacher=totw,hot_word_about_teacher=totr)



def get_hold_t_evaluation(u_id):
	course_list = CourseTimetable.objects.filter(teacher_id=u_id)#获取教师执教课程
	v_list = [] #结果list
	for course in course_list:
		class_admin = course.class_admin
		class_admin_list = []
		class_admin_list = class_admin.split(',')
		for i in class_admin_list:
			class_admin =ClassAdmin.objects.get(id=i)
			v_list.append({'class_id':class_admin.id,'course_name':course.name,'class_name':class_admin.name})
	return v_list


def save_ev_c(request):
	class_id = request.POST['class_id']
	t_id = request.session.get('u_id')
	classroom_discipline = request.POST['classroom_discipline']
	homework_quality = request.POST['homework_quality']
	study_atmosphere = request.POST['study_atmosphere']
	student_potential = request.POST['student_potential']
	text_eval = request.POST['text_eval']
	t_e_class.objects.create(teacher_id=t_id,course_class=class_id,classroom_discipline=classroom_discipline,homework_quality=homework_quality,study_atmosphere=study_atmosphere,student_potential=student_potential,proposal_of_class=text_eval)



def save_ev_o(request):
	t_id = request.session.get('u_id')
	teaching_program = request.POST['EvalTeachingProg[text]']
	organization_advice = request.POST['EvalOrg[text]']
	organization=''
	if 'EvalOrg[org_1]' in request.POST:
		org_1 = request.POST['EvalOrg[org_1]']
		organization=organization+','+org_1
	if 'EvalOrg[org_2]' in request.POST:
		org_2 =request.POST['EvalOrg[org_2]']
		organization=organization+','+org_2
	if 'EvalOrg[org_3]' in request.POST:
		org_3 =request.POST['EvalOrg[org_3]']
		organization=organization+','+org_3
	if 'EvalOrg[org_4]' in request.POST:
		org_4 =request.POST['EvalOrg[org_4]']
		organization=organization+','+org_4
	if 'EvalOrg[org_5]' in request.POST:
		org_5 =request.POST['EvalOrg[org_5]']
		organization=organization+','+org_5
	if 'EvalOrg[org_6]' in request.POST:
		org_6 =request.POST['EvalOrg[org_6]']
		organization=organization+','+org_6 
	t_e_o.objects.create(teacher_id=t_id,teaching_program=teaching_program,organization=organization[1:],organization_advice=organization_advice)



def get_advice(data_type,term): 
	advice_str=s_e_advice.objects.filter(year_term=term.year_term,environment_type=data_type)[0]
	advice_list = advice_str.advice.split('#')
	return advice_list